﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Globalization;

namespace GoogleMaps
{
	/// <summary>
	/// A collection of GLatLng objects.
	/// </summary>
	public class GLatLngCollection : Collection<GLatLng>
	{
		/// <summary>
		/// Initializes a new instance of the GLatLngCollection class.
		/// </summary>
		public GLatLngCollection()
			: base(new List<GLatLng>())
		{
		}

		/// <summary>
		/// Coverts this collection into a javascript array.
		/// </summary>
		public string ToJavaScriptArray()
		{
			StringBuilder sb = new StringBuilder();
			foreach (GLatLng ll in Items)
				sb.AppendFormat("{0}{1}", (sb.Length > 0) ? "," : "", ll.Render());

			return String.Format(CultureInfo.InvariantCulture, "[{0}]", sb.ToString());
		}
	}
}
